package br.ufrj.dcc.fes20112;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BufferedHeader;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class EventosOnlineActivity extends Activity {
	
	String enderecoPraLogin="http://www.dcc.ufrj.br/~samoraes/fes.php";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    public void clicouLogin(View view){
    	Intent i = new Intent(EventosOnlineActivity.this, EfetuouLogin.class);
    	
    	String contentWeb = getResponseLogin(((EditText) findViewById(R.id.entradaIdUsuario)).getText().toString(),((EditText) findViewById(R.id.entradaSenhaUsuario)).getText().toString());
    	
		Bundle b=new Bundle();
		b.putString("login",((EditText) findViewById(R.id.entradaIdUsuario)).getText().toString());
		b.putString("web", contentWeb);
		i.putExtras(b);
    	startActivity(i);
    }
	private String getResponseLogin(String login,String senha) {
		// TODO Auto-generated method stub
		String params="?login="+login+"&password="+senha;
		HttpClient client = new DefaultHttpClient();
		HttpGet request = new HttpGet(enderecoPraLogin+params);
		try {
			HttpResponse response = client.execute(request);
			BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
			String line ="$";
			line = rd.readLine();
			return line;
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			return "erro";
		} catch (IOException e) {
			// TODO Auto-generated catch block
			return "erro";
		}
		
		
	}
}